package com.zjw.zy.heart.configuration;

import com.zjw.zy.heart.utils.LogUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;

import java.util.concurrent.*;

@Configuration
@EnableAsync
public class TaskPool {

    private static final String TAG = "TaskPool";

    public static final String CONCURRENT_POOL = TAG + "_CONCURRENT_POOL";

    private static Executor concurrentPool;

    @Bean(CONCURRENT_POOL)
    public Executor concurrentPool() {
        return concurrentPool = new ThreadPoolExecutor(10, 1000,
                60L, TimeUnit.SECONDS,
                new SynchronousQueue<>(),
                (r, executor) -> LogUtils.e(TAG, "reject task:" + r));
    }

    public static Executor getConcurrentPool() {
        return concurrentPool;
    }
}
